
import os , sys
# 调试模式 引用代码
current_dir = os.path.dirname(os.path.abspath(__file__))
common_dir = os.path.abspath(os.path.join(current_dir,'..', '..','src'))
sys.path.append(common_dir)

'''

使用html页面做ui

# 启动服务
python capability_2_html.py server



# 访问页面

    文件路径: assets/pages/index.html
    http://127.0.0.1:5000/


    文件路径: assets/pages/home1.html
    http://127.0.0.1:5000/capability/capability_2_html/pages/home1.html


    文件路径: assets/pages/home2.html
    http://127.0.0.1:5000/capability/capability_2_html/pages/home2.html


    直接返回:
    http://127.0.0.1:5000/capability/capability_2_html/pages/return_html.html



    手动调用渲染返回页面:
    http://127.0.0.1:5000/capability/capability_2_html/pages/home_tmpl.html



'''

from pycapabilitydecorator  import capability



@capability.option(
    pages=["return_html.html"]
)
def return_html(params):
    '''
    直接返回html
    '''
    print("to_html")
    return "<html><body>home_tmpl</body></html>"




@capability.option(
    pages=["home_tmpl.html"]
)
def home_tmpl(params):
    '''
    返回渲染html页面
    '''
    return capability.render_page(
        # 模板文件
        "home3_tmpl.html",
        # 数据
        {
            "title": "这是手动加载模板",
            "content": "这是手动处理内容"
        }
    )

@capability.option()
def function2(params):
    return {
        "code": 0,
        "message": f"[function2]成功,params:{params}"
    }
